package Demo6;

import java.lang.reflect.Array;
import java.sql.SQLOutput;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Student {
    public int age;
    public String name;
    public float score;
    public Student (String name,int age,float score){
        this.age=age;
        this.name=name;
        this.score=score;
    }

    @Override
    public String toString() {
        return "student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }
}

class AgeComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.age-o2.age;
    }
}

class ScoreComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return (int) (o1.score-o2.score);
    }
}
//按照字符比较
class NameComparator implements Comparator<Student>{
    public int compare(Student o1,Student o2){
        return o1.name.compareTo(o2.name);//String类实现了Comparable接口并重写了compareTo方法，直接调用即可
    }
}
public class Test {

    public static void main(String[] args) {
        Student[] students=new Student[3];
        students[0]=new Student("laowu",45,45.23F);
        students[1]=new Student("zhangsan",25, 78.23F);
        students[2]=new Student("lsi",43,123.34F);
        AgeComparator ageComparator=new AgeComparator();
        //Arrays.sort(students,ageComparator);
        ScoreComparator scoreComparator=new ScoreComparator();
        Arrays.sort(students,scoreComparator);
        System.out.println(Arrays.toString(students));
    }
}